#!/bin/bash
set -e

echo "Compiling RealSense Depth Capture with Arm Control..."

# Check for required libraries
missing_libs=0
check_lib() {
    if ! ldconfig -p | grep -q $1; then
        echo "Error: Library $1 not found. Please install it first."
        missing_libs=1
    fi
}

# Check all required libraries
check_lib librealsense
check_lib libpng
check_lib libserial
check_lib libjson-c

if [ $missing_libs -ne 0 ]; then
    echo "Missing required libraries. Please install them and try again."
    exit 1
fi

# Run make to build the application
chmod +x gcccompile.sh
./gcccompile.sh

if [ -f "rsdc" ]; then
    echo "Build successful! You can now run ./armTrain.sh"
    chmod +x rsdc
else
    echo "Build failed. Please check the error messages above."
    exit 1
fi 